﻿using AutoDeployForSims.Utility;
using AutoDeployForSims.View;
using AutoDeployForSims.ViewModel;
using MyUtility.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AutoDeployForSims
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        private List<Button> MenuButtons = new List<Button>();
        private VersionControl MyVersionControl = new VersionControl();
        private TestControl MyTestControl = new TestControl();
        private CFGAnalysisControl MyCFGAnalysisControl = new CFGAnalysisControl();
        private AllStatusDisplayControl MyAllStatusDiaplayControl = new AllStatusDisplayControl();

        private AllStatusDisplayControlViewModel AllStatusDisplayControlVM = SingletonProvider<AllStatusDisplayControlViewModel>.Instance;

        public MainWindow()
        {
            InitializeComponent();
            AddButtonToList();
            //默认显示
            GUIOpt.UpdataViewDocument(MyCFGAnalysisControl);

            AllStatusDisplayControlVM.Start();
        }

        /// <summary>
        /// 用于将主界面按钮手动添加至列表中
        /// </summary>
        private void AddButtonToList()
        {
            MenuButtons.Add(MainInfoBtn);
            MenuButtons.Add(SetInfoBtn);
            MenuButtons.Add(ToolSupportBtn);
            MenuButtons.Add(ResourceBtn);
            MenuButtons.Add(LogBtn);
            MenuButtons.Add(HelpBtn);
            MenuButtons.Add(VersionBtn);
        }
             

        private void windowMinBtn_Click(object sender, RoutedEventArgs e)
        {
            this.WindowState = WindowState.Minimized;
        }

        private void windowMaxBtn_Click(object sender, RoutedEventArgs e)
        {
            if (this.WindowState == WindowState.Maximized)
            {
                this.WindowState = WindowState.Normal;
            }
            else if (this.WindowState == WindowState.Normal)
            {
                this.WindowState = WindowState.Maximized;
            }
        }

        private void windowCloseBtn_Click(object sender, RoutedEventArgs e)
        {
            Application.Current.Shutdown();
        }



        private void Border_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.ChangedButton == MouseButton.Left)
            {
                this.DragMove();
            }
        }

        private void MainInfoBtn_Click(object sender, RoutedEventArgs e)
        {
            Button clickedButton = sender as Button;
            if (clickedButton != null)
            {
                // 将被点击的按钮设置为选中样式  
                clickedButton.Style = (Style)FindResource("menuButtonSelected");

                //切换主界面
                GUIOpt.UpdataViewDocument(MyAllStatusDiaplayControl);
                //刷新样式
                MenuSelectedFlashStyle(clickedButton);
            }

        }

        private void VersionBtn_Click(object sender, RoutedEventArgs e)
        {
            Button clickedButton = sender as Button;
            if (clickedButton != null)
            {
                // 将被点击的按钮设置为选中样式  
                clickedButton.Style = (Style)FindResource("menuButtonSelected");

                //切换主界面
                GUIOpt.UpdataViewDocument(MyVersionControl);
                //刷新样式
                MenuSelectedFlashStyle(clickedButton);
            }
        }

        
        /// <summary>
        /// 刷新主界面菜单按钮的样式
        /// </summary>
        /// <param name="clickButton"></param>
        private void MenuSelectedFlashStyle(Button clickButton)
        {
            Style unSelected = (Style)FindResource("menuButton2");
            foreach (Button item in MenuButtons)
            {
                if (item != clickButton)
                {
                    item.Style = unSelected;
                }
            }
            
        }

        private void LogBtn_Click(object sender, RoutedEventArgs e)
        {

        }

        private void ResourceBtn_Click(object sender, RoutedEventArgs e)
        {
            Button clickedButton = sender as Button;
            if (clickedButton != null)
            {
                // 将被点击的按钮设置为选中样式  
                clickedButton.Style = (Style)FindResource("menuButtonSelected");

                //切换主界面
                GUIOpt.UpdataViewDocument(MyTestControl);
                //刷新样式
                MenuSelectedFlashStyle(clickedButton);
            }
        }

        private void SetInfoBtn_Click(object sender, RoutedEventArgs e)
        {
            Button clickedButton = sender as Button;
            if (clickedButton != null)
            {
                // 将被点击的按钮设置为选中样式  
                clickedButton.Style = (Style)FindResource("menuButtonSelected");

                //切换主界面
                GUIOpt.UpdataViewDocument(MyCFGAnalysisControl);
                //刷新样式
                MenuSelectedFlashStyle(clickedButton);
            }
        }

        private void ToolSupportBtn_Click(object sender, RoutedEventArgs e)
        {

        }

        private void HelpBtn_Click(object sender, RoutedEventArgs e)
        {

        }
    }
}
